package com.mymvc.controller.retval;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 王俊彪
 * @version 1.0
 */
@Controller
@RequestMapping("/order")
public class OrderController {

    /*返回void*/
    /*请求转发*/
    @GetMapping("/list.do")
    public void list(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setAttribute("list","在数据库中查询订单信息");
        request.getRequestDispatcher("/WEB-INF/jsp/orderList.jsp").forward(request,response);
    }

    /*重定向*/
    @PostMapping("/update.do")
    public void update(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("在数据库中查询订单信息");
        response.sendRedirect(request.getContextPath()+"/order/list.do");
    }

    /*返回字符串*/
    /*返回一个视图名称*/
    @GetMapping("/list02.do")
    public String list02(){
        return "orderList";
    }
    /*返回转发字符串*/
    @GetMapping("/update02.do")
    public String update02(HttpServletRequest request,HttpServletResponse response){
        request.setAttribute("list","更新了数据库订单信息");
        return "forward:list.do";
    }


    @GetMapping("/update03.do")
    public String update03(HttpServletRequest request,HttpServletResponse response){
        System.out.println("更新了数据库订单信息");
        return  "redirect:list.do";
    }

}
